<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.w3.org/1999/xhtml">

<head th:replace="admin/_fragments_after :: head(~{::title})">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">
    <link rel="stylesheet" href="../../static/css/my.css" th:href="@{/css/my.css}">
    <title>分类管理</title>
</head>

<body class="m-bloght">
    <!--导航-->
    <nav th:replace="admin/_fragments_after :: menu(3)" id="nav" class="ui inverted attached segment m-padded-tb-mini m-shadow-small">
        <div class="ui container">
            <div class="ui inverted secondary stackable menu">
                <h2 class="ui teal header item">DyBlogs后台</h2>
                <a href="#" class="active red m-item item m-mobile-hide m-text-mini"><i class="home icon"></i>首页</a>
                <a href="#" class="m-item item m-mobile-hide m-text-mini"><i class="idea icon"></i>分类</a>
                <a href="#" class="m-item item m-mobile-hide m-text-mini"><i class="tags icon"></i>标签</a>
                <div class="right m-item m-mobile-hide menu">
                    <div class="ui dropdown item">
                        <div class="text">
                            <img src="../../static/images/dy.jpg" th:src="@{/images/dy.jpg}" alt="" class="ui avatar image">
                            丁宇
                        </div>
                        <i class="dropdown icon"></i>
                        <div class="menu">
                            <a href="#" class="item">注销</a>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--目录图标-->
        <!--menu_toggle按钮事件，让导航在手机端可以点击展开-->
        <a href="#" class="ui menu_toggle black icon button m-top-right m-mobile-show">
            <i class="sidebar icon"></i>
        </a>
    </nav>
    <!--二级导航-->
    <div class="ui attached pointing menu">
        <div class="ui container">
            <div class="right menu">
                <a href="#" class="item">发布</a>
                <a href="#" class="teal active item">列表</a>
            </div>
        </div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <!--中间内容-->
    <div class="m-container">
        <!--container自适应-->
        <div class="ui stackable container">
            <table class="ui center aligned celled table">
                <thead>
                    <tr>
                        <th></th>
                        <th>名称</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody id="tbody">

                </tbody>
                <tfoot>
                    <tr>
                        <th colspan="6">
                            <div class="ui mini right floated pagination menu">
                                <a class="icon item">
                                    <i class="left chevron icon"></i>
                                </a>
                                <a class="item selectPage">1</a>
                                <a class="item selectPage">2</a>
                                <a class="item selectPage">3</a>
                                <a class="item selectPage">4</a>
                                <a class="icon item">
                                    <i class="right chevron icon"></i>
                                </a>
                            </div>
                            <a href="/admintypesinput" class="ui mini left floated teal bafsic button">新增</a>
                        </th>
                    </tr>
                </tfoot>
            </table>
        </div>
        <!--修改-->
        <div class="ui first coupled modal" style="padding: 50px !important;">
            <div class="ui stackable container">
                <form action="#" method="POST" class="ui form">
                    <div class="field">
                        <div class="ui left labeled input">
                            <label class="ui teal basic label">名称</label>
                            <input type="text" name="indexPicture" value="">
                            <input type="hidden" name="code" value="">
                        </div>
                    </div>
                    <div class="ui right aligned container">
                        <button class="ui teal button submit">修改</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
    <br>
    <br>
    <br>
    <br>
    <br>
    <!--底部footer-->
    <footer th:replace="admin/_fragments_after :: footer" class="ui inverted vertical segment m-padded-tb-massive">
        <div class="ui center aligned container">
            <!--布局16份,3337-->
            <div class="ui inverted divided stackable grid">
                <div class="three wide column">
                    <div class="ui inverted link list">
                        <div class="item">
                            <img src="../../static/images/dymp.jpg" th:src="@{/images/dymp.jpg}" class="ui rounded image" alt="" style="width: 100px;">
                        </div>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced">最新博客</h4>
                    <!--竖着的列表-->
                    <div class="ui inverted link list">
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                        <a href="#" class="item">用户故事</a>
                    </div>
                </div>
                <div class="three wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced">联系我</h4>
                    <!--竖着的列表-->
                    <div class="ui inverted link list">
                        <a href="#" class="item">Email：dyinin@qq.com</a>
                        <a href="#" class="item">QQ:2985922950</a>
                    </div>
                </div>
                <div class="seven wide column">
                    <h4 class="ui inverted header m-text-thin m-text-spaced">dingyu</h4>
                    <!--竖着的列表-->
                    <div class="ui inverted link list m-text-thin m-text-spaced m-opacity-mini">
                        <p>这是我的个人博客</p>
                    </div>
                </div>
            </div>
            <div class="ui inverted section divider"></div>
            <p class="m-text-thin m-text-spaced m-opacity-mini">Copyright © 2020-2021 DingYu Designed by DingYu</p>
        </div>
    </footer>
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.js"></script>
    <script>
        $(".menu_toggle").click(function () {
            $(".m-item").toggleClass("m-mobile-hide");
        })
        /**头像**/
        $('.ui.dropdown').dropdown({
            on: "click"
        })
    </script>
    <script>
        $(function(){
            queryType(0);
        });
        //全查询
        function queryType(page){
            $.ajax({
                url:"/type/query?page="+page,
                type:"post",
                success: function(data){
                    // alert(JSON.stringify(data));
                    var num=0;
                    $.each(data.records, function(i,j){
                        num++;
                        $("#tbody").append("<tr>" +
                            "<td>"+num+"</td>" +
                            "<td class='typeid' style='display:none'>"+j.code+"</td>" +
                            "<td>"+j.name+"</td>" +
                            "<td><a href='javascript:void(0)' onclick='queryByCode(\""+j.code+"\")' class='ui mini teal button'>编辑</a><button onclick='delete1(\""+j.code+"\");' class='ui deletetype mini red button'>删除</button></td>" +
                            "</tr>>")

                    })
                }

            })
        }
        //分页
        $(".selectPage").on("click",function(){
            $("#tbody tr").remove();
            var page=$(this).text();
            queryType(page);
        })
        //删除
        function delete1(code){
            $.ajax({
                url:"type/deleteType?code="+code,
                type:'GET',
                success: function(data){
                    alert(data);
                    if(data.code=="200"){
                        window.location.href='/admintypes';
                    }
                }
            })
        }
        //根据code单查询
        function queryByCode(code){
            $('.first.modal')
                .modal({
                    allowMultiple: true
                })
                .modal('show');
            $.ajax({
                url:'/type/queryTypeByCode?code='+code,
                type:'POST',
                success: function(data){
                    //alert(JSON.stringify(data));
                    $("input[name=indexPicture]").val(data.data.name);
                    $("input[name=code]").val(data.data.code);
                }
            });
        }
        //修改
        $(".submit").on('click',function(){
            var name=$("input[name=indexPicture]").val();
            var code=$("input[name=code]").val();
            if(name == null || name == ""){
                alert("name为空");
                return false;
            }

            $.ajax({
                url:'/type/updateType?code='+code+'&name='+name,
                type:'POST',
                success: function(data){
                    if(data.msg=="erro"){
                        alert("参数为空");
                    }
                    window.location.href='/admintypes';
                }
            });
        })
    </script>
</body>

</html>